package demo16_volatile;

import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @author kunkun
 * @className Test01_JMM
 * @Description JMM操作同一变量存在的问题展示
 * @date 2025/3/7 16:29
 */
public class Test01_JMM {

    static boolean flag = true;

    public static void main(String[] args) throws InterruptedException {
        //1. 开启线程
        new Thread(()->{
            while (flag){
            };
        }).start();

        //2. 改变flag，无法关闭子线程
        TimeUnit.SECONDS.sleep(1);
        flag=!flag;
        System.out.println("线程持续执行，无法关闭");


    }



}
